home *** CD-ROM | disk | FTP | other *** search
- Path: strauss.udel.edu!not-for-mail
- From: jcorig@strauss.udel.edu (John Pat Corigliano)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: SasC linker Error:
- Date: 28 Feb 1996 01:49:03 -0500
- Organization: University of Delaware
- Message-ID: <4h0tsv$dsi@strauss.udel.edu>
- References: <dkauppDnEzzs.FsD@netcom.com> <758.6631T1348T796@sn.no>
- NNTP-Posting-Host: strauss.udel.edu
-
- In article <758.6631T1348T796@sn.no>, Christopher Naas <christon@sn.no> wrote:
- >Blitter wrote:
- >
- >> Can someone tell me what may be causing these errors? MOBtrigger is a
- >>BOOL and as far a I know, its just changed using TRUE and FALSE.
- >
- >>ERROR: Multiply defined symbol '_MOBtrigger'.
- >> First defined in file 'comm.o'.
- >> Type = RELOCATABLE Value = 1010
- >> Redefined in file 'special.o'.
- >> Type = RELOCATABLE Value = 9
- >[..]
- >
- >You probably have a Global.h or such with "BOOL MOBTrigger = ..;" .. replace
- >this with "BOOL MOBTrigger;", and it should work.
-
- No, that won't work. A global variable can only be declared once. The
- "=" doesn't matter since both are declarations. You need to declare
- MOBTrigger in one file only. Any other files that use MOBTrigger need
- to define it as "extern". So, in main.c you might have:
- BOOL MOBTrigger = FALSE;
- And in some_other_file.c have:
- extern BOOL MOBTrigger;
-
- I like to use one header file that contains the declarations of all global
- variables. The "trick" to doing this is to create a macro like so:
-
- #ifdef MAIN_C
- #define Global
- #define Init(var, val) var = val
- #else
- #define Global extern
- #define Init(var, val) var
- #endif
-
- Then you can declare your global variables like this:
-
- Global int x;
- Global BOOL Init(flag, FALSE);
- etc...
-
- If this file is called "vars.h", one file includes it like this:
-
- #define MAIN_C
- #include "vars.h"
- #undef MAIN_C
-
- And all other files simply #include "vars.h".
-
- One implication to this is that the file that defines MAIN_C must
- be re-compiled whenever a new variable is added to "vars.h". This
- is simply handled by adding "vars.h" to the dependency list of that
- file.
-
- I hope someone finds this info useful :)
- --
- John Corigliano jcorig@strauss.udel.edu
- Computer and Information Science University of Delaware
- --
- "Never drive a car when you're dead." - Tom Waits
-